package com.dmzc.stage2.chapter24;

import java.util.concurrent.TimeUnit;

import static java.util.concurrent.ThreadLocalRandom.current;

public class TaskHandler implements Runnable {
    private final Request request;

    public TaskHandler(Request request) {
        this.request = request;
    }

    @Override
    public void run() {
        System.out.println("begin handle"+request);
        slowly();
        System.out.println("end handle"+request);
    }
    private void slowly(){
        try {
            TimeUnit.SECONDS.sleep(current().nextInt());
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}
